import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

class TestFittedBoxWidget extends StatefulWidget {
  const TestFittedBoxWidget({super.key});

  @override
  State<TestFittedBoxWidget> createState() {
    return _FittedBoxState();
  }
}

class _FittedBoxState extends State<TestFittedBoxWidget> {
  Widget wContainer(BoxFit boxFit) {
    return Container(
      width: 50,
      height: 50,
      color: Colors.red,
      child: FittedBox(
        fit: boxFit,
        // 子容器超过父容器大小
        child: Container(
          width: 60,
          height: 70,
          color: Colors.blue,
          child: Text("123456789"),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    // 头像
    Widget avatar = Image.asset("images/ic_launcher.png", width: 60.0);
    return Scaffold(
      appBar: AppBar(
        title: const Text("基础 FittedBox "),
      ),
      body: SingleChildScrollView(
        scrollDirection: Axis.vertical,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text('子组件大小超出了父组件大小时，如果不经过处理的话 Flutter 中就会显示一个溢出警告并在控制台打印错误日志，比如下面代码会导致溢出'),

            wContainer(BoxFit.none),
            Text('BoxFit.none 含义是不做任何限制'),
            wContainer(BoxFit.contain),
            Text('BoxFit.contain 含义是按照子组件的比例缩放(默认)'),
            wContainer(BoxFit.fill),
            Text('BoxFit.fill 含义是'),
            wContainer(BoxFit.cover),
            Text('BoxFit.cover 含义是按照子组件的比例缩放'),
            wContainer(BoxFit.fitHeight),
            Text('BoxFit.fitHeight 含义是按照子组件的比例缩放'),
            wContainer(BoxFit.fitWidth),
            Text('BoxFit.fitWidth 含义是按照子组件的比例缩放'),
            wContainer(BoxFit.scaleDown),
            Text('BoxFit.scaleDown 含义是按照子组件的比例缩放'),
          ],
        ),
      ),
    );
  }
}
